package com.jd.event.service;

import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;

import com.jd.event.Event;
import com.jd.event.EventContainer;
import com.jd.event.EventListener;
import com.jd.event.ScheduledEventObject;

public class GroupScheduledService implements ScheduledService {
	protected  String group;
	protected EventContainer container = null;


	
    public GroupScheduledService(){}
	public GroupScheduledService(String group,EventContainer container) {
		this.group = group;
		this.container=container;
	}
	

	@Override
	public void submit(Event<?> event) {
		container.getReposity().addEvent(group, event);
	}

	@Override
	public void submit(Event<?> event, List<EventListener> listeners) {
		container.addListeners(group, listeners);
		this.submit(event);		
	}

	
	@Override
	public void scheduleAtTime(Date time, Callable<?> callable) {
		ScheduledEventObject<Callable<?>> event=new ScheduledEventObject<Callable<?>>();
		event.setId("event_task"+time.toString()+Math.random());
		event.setEventTime(time);
		event.setObject(callable);
		this.submit(event);
	} 
	
	public void setGroup(String group) {
		this.group = group;
	}
	public void setContainer(EventContainer container) {
		this.container = container;
	}

}
